// pages/person1/person1.js
var indexData = require("../indexdata/indexdata.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: "王先生",
    tel: "135 **** 2060",
    shoppingNumber: '3',
    personImg:'../images/person1/person.png',
    person02HeadR:false,// 余额金额是否显示，false显示
    delivery:{
      'danhao':'配送中：订单号 EDDSF231312312 ',
      'gongji':'368',
      'yisong':'204',
      'daisong':'164',
      'jiezhi':'09-16'
    },
    deliveryToday:[
      [
        {
          "index":"0-0",
          "head": '今日配送',
          'productImg': '../images/index/4.png',
          'productName': '11益生菌发酵乳',
          'productNumber': '数量：9',
          'producPrice':'订单余额：145.90',
          'productAddress': '济南市环保环保科技园国际商务中心F座/南6031济南市环保环保科技园国际商务中心F座',
          'productTime': '11-17',//今日配送时间
          'NodeliveryToday': false,//是否开通此功能，false否
          'starRiqi': '2021-03-10',//下单日期
          'starTime': '截止日期',//下单时间
          'beginRiqi': '11-03',//开始配送日期
          'beginTime': '10:26',//开始配送时间
          'todayRiqi': '11-17',//今日配送日期
          'todayTime': '17:30',//今日配送时间
          'shouhuoRiqi': '11-17',//收货日期
          // 'shouhuoTime': '17:30',//收货时间
        },
        {
          "index": "0-1",
          "head": '今日配送',
          'productImg': '../images/index/4.png',
          'productName': '一二三四五六七八九十',
          'productNumber': '数量：8',
          'producPrice': '订单余额：145.90',
          'productAddress': '山东省济南市历城区 鲍山街道 工工业南路殷陈小区4号楼2单元',
          'productTime': '11-16',//今日配送时间
          'NodeliveryToday': false,//是否开通此功能，false否
          'starRiqi': '11-01',//下单日期
          'starTime': '15:27',//下单时间
          'beginRiqi': '11-03',//开始配送日期
          'beginTime': '10:26',//开始配送时间
          'todayRiqi': '11-16',//今日配送日期
          'todayTime': '17:30',//今日配送时间
          'shouhuoRiqi': '11-16',//收货日期
          'shouhuoTime': '17:30',//收货时间          
        },   
      ],
      [
        {
          "index": "1-0",
          "head": '13今日配送',
          'productImg': '../images/index/4.png',
          'productName': '益生菌发酵乳',
          'productNumber': '数量：5',
          'producPrice': '订单余额：14.90',
          'productAddress': '山东省济南市历城区 鲍山街道 工工业南路殷陈小区2号楼2单元',
          'productTime': '11-27',
          'NodeliveryToday': false,//是否开通此功能，false否
          'starRiqi': '11-21',//下单日期
          'starTime': '15:27',//下单时间
          'beginRiqi': '11-23',//开始配送日期
          'beginTime': '10:26',//开始配送时间
          'todayRiqi': '11-27',//今日配送日期
          'todayTime': '17:30',//今日配送时间
          'shouhuoRiqi': '11-27',//收货日期
          'shouhuoTime': '17:30',//收货时间          
        },
        {
          "index": "1-1",
          "head": '今日配送',
          'productImg': '../images/index/4.png',
          'productName': '益生菌发酵乳',
          'productNumber': '数量：1',
          'producPrice': '订单余额：145.90',
          'productAddress': '济南市环保环保科技园国际商务中心F座/南6031济南市环保环保科技园国际商务中心F座',
          'productTime': '11-17',//今日配送时间
          'NodeliveryToday': false,//是否开通此功能，false否
          'starRiqi': '11-01',//下单日期
          'starTime': '15:27',//下单时间
          'beginRiqi': '11-03',//开始配送日期
          'beginTime': '10:26',//开始配送时间
          'todayRiqi': '11-17',//今日配送日期
          'todayTime': '17:30',//今日配送时间
          'shouhuoRiqi': '11-17',//收货日期
          'shouhuoTime': '17:30',//收货时间          
        },   
      ]
   
    ],
    logisticsPopup:{//物流弹出框内容
      'productImg': '../images/index/4.png',
      'productName': '益生菌发酵乳',
      'productNumber': '数量：134',
      'producPrice': '订单余额：145.90',
      'productAddress': '济南市环保环保科技园国际商务中心F座/南6031济南市环保环保科技园国际商务中心F座',
      'productTime': '11-17',//今日配送时间
      'starRiqi': '11-01',//下单日期
      'starTime': '15:27',//下单时间
      'beginRiqi': '11-03',//开始配送日期
      'beginTime': '10:26',//开始配送时间
      'todayRiqi': '11-17',//今日配送日期
      'todayTime': '17:30',//今日配送时间
      'shouhuoRiqi': '11-17',//收货日期
      'shouhuoTime': '17:30',//收货时间
    },
    logisticsPopupBtn: true,//物流弹出框内容true隐藏，隐藏显示
    detail0: [
      {
        image: "../images/deliveryToday/daifukuan.png",
        text: "待付款",
        id: "../myOrder/myOrder"
      },
      {
        image: "../images/deliveryToday/peisongzhong.png",
        text: "配送中",
        id: "../myOrder/myOrder"
      },
      {
        image: "../images/deliveryToday/lishidingdan.png",
        text: "历史订单",
        id: "../myOrder/myOrder"
      },
      {
        image: "../images/deliveryToday/changting.png",
        text: "长停中",
        id: "../myOrder/myOrder"
      },

    ],    
    detail1: [
      {
        image: "../images/person1/wodedingdan.png",
        text: "我的订单",
        id: "../myOrder/myOrder"
      },
      {
        image: "../images/person1/yueduizhangdan.png",
        text: "月对账单",
        id: "../monthlyStatement/monthlyStatement"
      },
      {
        image: "../images/person1/xiaofeimingxi.png",
        text: "消费明细",
        id: "../consumptionDetails/consumptionDetails"
      },
      {
        image: "../images/person1/jiaokuanchaxun.png",
        text: "交款查询",
        id: "../paymentRecord/paymentRecord"
      },

    ],
    detail2: [
      {
        image: "../images/person1/dizhiguanli.png",
        text: "地址管理",
        id: "../address/address"
      },

    ],  
    shoppingNumber: '3',
    thNumber: [1, 2, 3, 4, 5, 6],
    elasticFrameBtn1: true,
    elasticFrameBtn2: true,
    thPatternEwm: '../images/person/ewm.png',
    paidanShow: {
      zhuangxiangBtn: true,
      xiguan: true,
      yaoshi: true,
      qita: true
    },
    paidanTextarea: {
      textareaText: '',
      textareaCustomer: true,
      qitaSuccess: true,
      customerNumber: 2
    },
    tabBar: indexData.tabBar,//tabar
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // wx.setTabBarBadge({//购物车数量
    //   index: 1,
    //   text: this.data.shoppingNumber,
    //   color: "black"
    // });
    this.setData({
      tabBar: indexData.tabBar,//tabar
    })
  },
  onReady: function () {
    // tabar选中状态
    var tabBar = this.data.tabBar;
    tabBar[0].select = false;
    tabBar[1].select = false;
    tabBar[2].select = false;
    tabBar[3].select = true;
    this.setData({
      tabBar: tabBar
    })
  },  
  goHtml: function (event) {
    var newsid = event.currentTarget.dataset.newsid
    wx.navigateTo({
      url: newsid
      // 跳转各个页面详情
    })
  },
  goBiangeng: function (event) {//跳到变更
    var newsid = event.currentTarget.dataset.newsid
    wx.navigateTo({
      url: newsid
    })
  },
  goPaidan: function (event) {//派单
    var newsid = event.currentTarget.dataset.newsid;
    var paidanShow = this.data.paidanShow
    if (newsid == 'zhuangxiang') {
      paidanShow.zhuangxiangBtn = false
    } else if (newsid == 'xiguan') {
      paidanShow.xiguan = false

    } else if (newsid == 'yaoshi') {
      paidanShow.yaoshi = false

    } else if (newsid == 'qita') {
      paidanShow.qita = false

    }
    this.setData({
      paidanShow: paidanShow
    })
    this.qitaBtn()
  },
  //提货方式
  patternNumber: function () {
    wx.hideTabBar();//隐藏tabBar
    var elasticFrameBtn1 = this.data.elasticFrameBtn1;
    elasticFrameBtn1 = false;
    this.setData({
      elasticFrameBtn1: elasticFrameBtn1
    })

  },
  elasticFrameHide: function () {
    this.setData({
      elasticFrameBtn1: true,
      elasticFrameBtn2: true,
    })
    wx.showTabBar();//显示tabBar
  },
  patternEwm: function () {
    wx.hideTabBar();//隐藏tabBar
    var elasticFrameBtn2 = this.data.elasticFrameBtn1;
    elasticFrameBtn2 = false;
    this.setData({
      elasticFrameBtn2: elasticFrameBtn2
    })
  },
  qitaBtnHide: function () {
    var paidanShow = this.data.paidanShow
    paidanShow.zhuangxiangBtn = true
    paidanShow.xiguan = true
    paidanShow.yaoshi = true
    paidanShow.qita = true
    this.setData({
      paidanShow: paidanShow
    })
  },
  paidanBtnHide: function () {
    var paidanShow = this.data.paidanShow
    paidanShow.zhuangxiangBtn = true
    paidanShow.xiguan = true
    paidanShow.yaoshi = true
    paidanShow.qita = true
    this.setData({
      paidanShow: paidanShow
    })
    var paidanShow = this.data.paidanShow
    paidanShow.qita = true;
    var paidanTextarea = this.data.paidanTextarea;
    paidanTextarea.qitaSuccess = false;
    this.setData({
      paidanShow: paidanShow,
      paidanTextarea: paidanTextarea
    })
    this.qitaDown()
  },
  // 其他派单
  qitaBtn: function () {
    var paidanTextarea = this.data.paidanTextarea;
    paidanTextarea.qitaBtn = !paidanTextarea.qitaBtn;
    paidanTextarea.textareaCustomer = true;
    paidanTextarea.textareaText = ''
    this.setData({
      paidanTextarea: paidanTextarea
    })
  },
  qitaBtnSuccess: function () {
    var paidanShow = this.data.paidanShow
    paidanShow.qita = true;
    var paidanTextarea = this.data.paidanTextarea;
    paidanTextarea.qitaSuccess = false;
    this.setData({
      paidanShow: paidanShow,
      paidanTextarea: paidanTextarea
    })
    this.qitaDown()

  },
  qitaBtnSuccessHide: function () {
    var paidanTextarea = this.data.paidanTextarea;
    paidanTextarea.qitaSuccess = true;
    this.setData({
      paidanTextarea: paidanTextarea
    });
  },
  qitaDown() { //倒计时函数
    var that = this
    var customerDown = setInterval(function () {
      var paidanTextarea = that.data.paidanTextarea;
      var customerNumber = paidanTextarea.customerNumber;
      if (customerNumber <= 1) {
        customerNumber = 2
        paidanTextarea.qitaSuccess = true
        that.setData({
          paidanTextarea: paidanTextarea
        })
        clearInterval(customerDown);

      } else {
        customerNumber--;

      }
      paidanTextarea.customerNumber = customerNumber
      that.setData({
        paidanTextarea: paidanTextarea
      })
    }, 1000);

  },
  textareaqita(e) {//其他留言
    var paidanTextarea = this.data.paidanTextarea;
    paidanTextarea.textareaCustomer = e.detail.value.replace(/\s+/g, '');
    paidanTextarea.textareaText = paidanTextarea.textareaCustomer
    this.setData({
      paidanTextarea: paidanTextarea
    });
    this.qitaText()
  },
  qitaText: function () {
    var paidanTextarea = this.data.paidanTextarea;
    if (this.data.paidanTextarea.textareaCustomer) {
      this.data.paidanTextarea.textareaCustomer = false;
      this.data.paidanTextarea.customerNumber = 2
      this.setData({
        paidanTextarea: paidanTextarea
      });
    } else {
      this.data.paidanTextarea.textareaCustomer = true
      this.setData({
        paidanTextarea: paidanTextarea
      });
    }
  },
  gomyOrder: function () {//跳转到历史订单我的订单
    wx.navigateTo({
      url: '../myOrder/myOrder'
    })
  },
  logisticsPopup:function(event){//物流弹出框显示隐藏
    var index = event.currentTarget.dataset.newsid;
    var deliveryToday = this.data.deliveryToday;
    var logisticsPopup = this.data.logisticsPopup
    var countIndex = index.split("-");
    
    logisticsPopup.productImg = deliveryToday[countIndex[0]][countIndex[1]].productImg
    logisticsPopup.productName = deliveryToday[countIndex[0]][countIndex[1]].productName
    logisticsPopup.productNumber = deliveryToday[countIndex[0]][countIndex[1]].productNumber
    logisticsPopup.productAddress = deliveryToday[countIndex[0]][countIndex[1]].productAddress
    logisticsPopup.productTime = deliveryToday[countIndex[0]][countIndex[1]].productTime
    logisticsPopup.starRiqi = deliveryToday[countIndex[0]][countIndex[1]].starRiqi
    logisticsPopup.starTime = deliveryToday[countIndex[0]][countIndex[1]].starTime
    logisticsPopup.beginRiqi = deliveryToday[countIndex[0]][countIndex[1]].beginRiqi
    logisticsPopup.beginTime = deliveryToday[countIndex[0]][countIndex[1]].beginTime
    logisticsPopup.todayRiqi = deliveryToday[countIndex[0]][countIndex[1]].todayRiqi
    logisticsPopup.todayTime = deliveryToday[countIndex[0]][countIndex[1]].todayTime
    logisticsPopup.shouhuoRiqi = deliveryToday[countIndex[0]][countIndex[1]].shouhuoRiqi
    logisticsPopup.shouhuoTime = deliveryToday[countIndex[0]][countIndex[1]].shouhuoTime 
    this.setData({
      logisticsPopup: logisticsPopup,
      logisticsPopupBtn:false
    });      
  },
  logisticsPopupHide: function () {//物流弹出框隐藏
    this.setData({
      logisticsPopupBtn: true
    });
  },
  goTabBar: function (event) {
    var newsid = event.currentTarget.dataset.newsid;
    wx.redirectTo({
      url: newsid
      // 跳转tabBar
    })
  },   

})